import * as THREE from "three";
import TWEEN from '@tweenjs/tween.js';
// 从threejs扩展库引入gui.js
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';

var width = window.innerWidth;
var height = window.innerHeight;
// 创建一个透明相机
const camera = new THREE.PerspectiveCamera(30, width / height, 1, 3000);
// // 设置相机的位置
camera.position.set(150, 150, 150);
const pos0 = camera.position.clone()
// 设置相机指向
camera.lookAt(0, 0, 0);
const dir = new THREE.Vector3();
camera.getWorldDirection(dir)//获取相机方向向量
const obj = {
    L:0
}
const tween = new TWEEN.Tween(obj).to(
    {L:100},3000).onUpdate((obj) => {
        console.log(obj.L);
        camera.position.copy(pos0.clone().add(dir.clone().multiplyScalar(obj.L)))
    }).start()

const gui = new GUI();
gui.add(obj,"L",0,200).name('修改相机位置').onChange((obj)=>{
    console.log(obj);
    camera.position.copy(pos0.clone().add(dir.clone().multiplyScalar(obj)))
})

function loop(){
    tween.update()
requestAnimationFrame(loop);
}
loop()

export default camera;